package com.abe.libquick.utils.quick;

import android.content.Context;

import com.abe.libcore.utils.context.ContextUtils;
import com.abe.libquick.R;

import java.lang.reflect.Field;

public class ResourceUtils {
    public static int getImageResId(String name) {
        Context context = ContextUtils.Companion.getContext();
        int r_id = 0x7f02000b;
        try {
            String resType = name.contains("menu") ? "mipmap" : "drawable";
            r_id = context.getResources().getIdentifier(name, resType, context.getPackageName());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("getImageResourceId:" + e.getMessage());
        }
        return r_id;
    }

    public static int getIDResourceId(String name) {
        Class id = R.id.class;
        Field field;
        int r_id = 0x7f02000b;
        try {
            field = id.getField(name);
            r_id = field.getInt(field.getName());
        } catch (Exception e) {
            e.printStackTrace();
            //System.out.println("getIDResourceId:" + e.getMessage());
        }
        return r_id;
    }
}